define(["jquery", "easy-admin"], function ($, ea) {
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'user.withdraw/index',
        add_url: 'user.withdraw/add',
        edit_url: 'user.withdraw/pass',
        delete_url: 'user.withdraw/fail',
        export_url: 'user.withdraw/export',
        modify_url: 'user.withdraw/modify',
    };
    var operat = ['edit', 'delete'];
    var Controller = {
        index: function () {
            ea.table.render({
                init: init,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '主键id',search:false},
                    {field: 'uid', title: '用户名',templet: function (res) {
                            return "<label>"+res.userWithdraw.username+"</label>"
                        }},
                    {field: 'cash_no', title: '提现单号'},
                    {field: 'cash_price', title: '提现金额',search:false},
                    {field: 'is_status', title: '状态',search:false,templet:function (res) {
                            if (res.is_status == 0){
                                return '<label style="color: #ffb800">提现中</label>'
                            }else if(res.is_status == 1){
                                return '<label style="color: #2ecc71">提现成功</label>'
                            }else {
                                return '<label style="color: red">提现失败</label>'
                            }
                        }},
                    {field: 'create_time', title: '提现时间',search:false},
                    // {width: 150, title: '操作', templet: ea.table.depositTool,operat},
                    {width: 150, title: '操作',  toolbar: '#barDemo',},
                ]],
            });
            ea.listen();
            layui.use(['table','jquery'], function(){
                var table = layui.table;
                var $ = layui.jquery;
                    $('body').on('click','.edit',function () {
                        var id = $(this).val()
                        var text = $(this).text()
                        layer.confirm(text + '吗？', function (index) {
                            $.ajax({
                                url: "pass",
                                data: {id},
                                success: (res) => {
                                    console.log(res)
                                    if (res.code == 0) {
                                        layer.msg(res.msg, {icon: 1, time: 2000}, function () {
                                            parent.location.reload()
                                        })
                                    } else {
                                        layer.msg(res.msg, {icon: 5, time: 2000})
                                    }
                                }
                            })
                        });
                    })
                $('body').on('click','.del',function () {
                    var id = $(this).val()
                    var text = $(this).text()
                    layer.confirm(text + '吗？', function (index) {
                        $.ajax({
                            url: "fail",
                            data: {id},
                            success: (res) => {
                                console.log(res)
                                if (res.code == 0) {
                                    layer.msg(res.msg, {icon: 1, time: 2000}, function () {
                                        parent.location.reload()
                                    })
                                } else {
                                    layer.msg(res.msg, {icon: 5, time: 2000})
                                }

                            }
                        })
                    });
                })
            });
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});

